function HTTP(obj, config) {

	if(obj.data.token == '') {
		uni.reLaunch({
			url:"/pages/account/login"
		})
		return
	}

	let defaultConfig = {
		loading: false
	}

	config = {
		...defaultConfig,
		...config
	}


	// 如果需要显示loading,mask防止点击穿透
	config.loading && uni.showLoading({
		title: '加载中',
		mask: true
	});


	return new Promise((resolve, reject) => {

		let options = {
			url: "",
			method: "GET",
			data: {},
			dataType: 'json',
			header: {
				"Content-Type": "application/x-www-form-urlencoded"
			},
			success: (res) => {
				uni.hideLoading();
				// 状态码为200
				if (res.statusCode === 200) {
					console.log("HTTP请求结果：", res.data)

					let data = res.data;

					//todo 缺少自动校验用户是否登录过期
					if (data.status === "101") {
						uni.showToast({
							title: "token过期!",
							icon: "none",
						})
						uni.reLaunch({
							url:"/pages/account/login"
						})
					}

					if(data.status !== '200') {
						uni.showToast({
							title: data.msg,
							icon: "none",
						})
					}

					resolve(data)

				} else {
					uni.showToast({
						title: '系统异常请稍后再试',
						icon: "none",
					})
					reject({
						errorCode: '99999',
						errorDesc: '系统异常请稍后再试',
						body: {}
					})
				}
			},
			fail: (err) => {
				uni.hideLoading();
				uni.showToast({
					title: "网络异常，请稍后再试!",
					icon: "none",
				})
				reject("网络异常，请稍后再试!");
			},
			complete: () => {}
		}

		options = {
			...options,
			...obj
		};

		if (options.url && options.method) {
			uni.request(options);
		} else {
			uni.showToast({
				title: 'HTTP：缺失参数', icon: "none"
			})
		}

	})

}



export default {
	GET(url, data = {}, config) {
		return HTTP({
			url,
			data,
			method: "GET"
		}, config);
	},
	POST(url, data = {}, config) {
		return HTTP({
			url,
			data,
			method: "POST"
		}, config);
	},
	POSTformdata(url, data = {}, config) {
		return HTTP({
			url,
			data,
			method: "POST"
		}, config);
	},
	POSTMultipartformdata(url, data = {}, config) {
		return HTTP({
			url,
			data,
			method: "POST",
			header: {
				"Content-Type": 'multipart/form-data'
			}
		}, config);
	},
}
